package com.longcai.piaojia.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.longcai.piaojia.R;
import com.longcai.piaojia.conn.MyBagListGet;
import com.longcai.piaojia.conn.OrderBalanceDetailGet;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.glide.GlideLoader;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.List;

/**
 * Created by Administrator on 2016/10/17.
 */
public class BalanceDetailListAdapter extends ArrayAdapter<OrderBalanceDetailGet.BalanceDetailEntity> {

    private LayoutInflater layoutInflater;
    private Context context;
    public BalanceDetailListAdapter(Context context, List<OrderBalanceDetailGet.BalanceDetailEntity> lists) {
        super(context, 0, lists);

        this.context = context;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;

        OrderBalanceDetailGet.BalanceDetailEntity balanceDetailEntity = getItem(position);

        if (convertView == null) {

            convertView = BoundViewHelper.boundView(viewHolder = new ViewHolder(), ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) layoutInflater.inflate(R.layout.item_balance_detail_list, null)));

            convertView.setTag(viewHolder);

        } else {

            viewHolder = (ViewHolder) convertView.getTag();

        }

        viewHolder.item_balance_time.setText(balanceDetailEntity.posttime);

        StringBuffer sb = new StringBuffer();

        //没准还得显示
//        if (balanceDetailEntity.balance_type.equals("1")) {
//
//            sb.append(context.getResources().getString(R.string.deposit_balance_text));
//
//        } else if (balanceDetailEntity.balance_type.equals("2")) {
//
//            sb.append(context.getResources().getString(R.string.deposit_huimin_balance_text));
//
//        }

        if (balanceDetailEntity.type.equals("1")) {

            sb.append(context.getResources().getString(R.string.deposit_balance_get_text));

            viewHolder.item_balance_money.setTextColor(ContextCompat.getColor(context, R.color.mine_tab_left_text_color));
            viewHolder.item_balance_money.setText(context.getResources().getString(R.string.goods_info_add_symbols_text) + balanceDetailEntity.money);

        } else if (balanceDetailEntity.type.equals("2")){

            sb.append(context.getResources().getString(R.string.deposit_balance_pay_text));

            viewHolder.item_balance_money.setTextColor(ContextCompat.getColor(context, R.color.title_center_text_color));
            viewHolder.item_balance_money.setText(context.getResources().getString(R.string.goods_info_symbols_text) + balanceDetailEntity.money);
        }

        viewHolder.item_balance_way.setText(sb.toString());


        return convertView;

    }

    private class ViewHolder {

        @BoundView(R.id.item_balance_way) private TextView item_balance_way;
        @BoundView(R.id.item_balance_time) private TextView item_balance_time;
        @BoundView(R.id.item_balance_money) private TextView item_balance_money;

    }

}
